#pragma once
#include <string>
#include <cstddef> 
#include <odb/core.hxx>
#include <odb/nullable.hxx>
#include <boost/date_time/posix_time/posix_time.hpp>

namespace xu
{
    #pragma db object
    class Message
    { 
    public:
        Message(){}
        Message (const std::string &message_id,const boost::posix_time::ptime &created_time,
            const std::string &from_user_id,const std::string &to_session_id,signed char message_type)
            :_message_id(message_id),
            _created_time(created_time),
            _from_user_id(from_user_id),
            _to_session_id(to_session_id),
            _message_type(message_type)
            {}

        std::string message_id(){return _message_id;}
        void message_id(const std::string & val){_message_id = val;}

        boost::posix_time::ptime created_time(){return _created_time;}
        void created_time(const boost::posix_time::ptime & val){_created_time = val;}

        std::string from_user_id(){return _from_user_id;}
        void from_user_id(const std::string & val){_from_user_id = val;}

        std::string to_session_id(){return _to_session_id;}
        void to_session_id(const std::string & val){_to_session_id = val;}

        signed char message_type(){return _message_type;}
        void message_type(signed char val){_message_type = val;}

        std::string content()
        {
            if(_content)
            {
                return *_content;
            }
            return std::string();
        }
        void content(const std::string & val){_content = val;}

        std::string file_id()
        {
            if(_file_id)
            {
                return *_file_id;
            }
            return std::string();
        }
        void file_id(const std::string & val){_file_id = val;}

        std::string filename()
        {
            if(_filename)
            {
                return *_filename;
            }
            return std::string();
        }
        void filename(const std::string & val){_filename = val;}

        unsigned long filesize()
        {
            if(_filesize)
            {
                return *_filesize;
            }
            return 0;
        }
        void filesize(unsigned long val){_filesize = val;}

    private:
        friend class odb::access;
        #pragma db id auto
        unsigned long _id;
        #pragma db unique type("VARCHAR(127)")
        std::string _message_id ;
        #pragma db type("TIMESTAMP") not_null 
        boost::posix_time::ptime _created_time;
        #pragma db type("VARCHAR(127)")
        std::string _from_user_id ;
        #pragma db type("VARCHAR(127)")
        std::string _to_session_id ;
        #pragma db not_null
        signed char _message_type ;
        odb::nullable<std::string> _content;
        #pragma db type("VARCHAR(127)")
        odb::nullable<std::string> _file_id ;
        #pragma db type("VARCHAR(127)")
        odb::nullable<std::string> _filename ;
        odb::nullable<unsigned long> _filesize;
    };
}

